package com.sxz.sbs.view;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.sxz.sbs.applibrary.component.LabelTextView;
import com.sxz.sbs.module.order.mode.OrderDetailBean;
import com.sxz.sbs.module.order.mode.OrderhandleBean;

import java.util.List;

/**
 * 标签布局
 */

public class LabelLinearLayout extends LinearLayout {
    private Context context;
    public LabelLinearLayout(Context context) {
        this(context,null);
    }

    public LabelLinearLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public LabelLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        setOrientation(HORIZONTAL);
    }
    public void setOrderDetailLabels (List<OrderDetailBean.DiscountBean> datas) {
        for (int i = 0; i < datas.size(); i++) {
            LabelTextView superTextView = new LabelTextView(context);
            superTextView.setText(datas.get(i).getTitle());
            superTextView.setTextSize(12);
            superTextView.setBackGround(Color.parseColor("#" + datas.get(i).getBackColor()));
            superTextView.setTextColor(Color.parseColor("#" + datas.get(i).getTextColor()));
            superTextView.setSingleLine();
            LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            lp.setMargins(5, 0, 5, 0);
            superTextView.setLayoutParams(lp);
            superTextView.setEllipsize(TextUtils.TruncateAt.END);
            addView(superTextView);
            if (i >= 4) {
                return;
            }
        }

    }
    public void setOrderListLabels (List<OrderhandleBean.ListBean.DiscountBean> datas) {
        for (int i = 0; i < datas.size(); i++) {
            LabelTextView superTextView = new LabelTextView(context);
            superTextView.setText(datas.get(i).getTitle());
            superTextView.setTextSize(12);
            superTextView.setBackGround(Color.parseColor("#" + datas.get(i).getBackColor()));
            superTextView.setTextColor(Color.parseColor("#" + datas.get(i).getTextColor()));
            superTextView.setSingleLine();
            LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            lp.setMargins(5, 0, 5, 0);
            superTextView.setLayoutParams(lp);
            superTextView.setEllipsize(TextUtils.TruncateAt.END);
            addView(superTextView);
            if (i >= 4) {
                return;
            }
        }

    }
    public void clearChild () {
        removeAllViews();
    }
}
